home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Software Explosion
/
Software Explosion (Fore-Matt Home Computing)(1996).iso
/
tetris
/
amiga
/
wbtris_1.3
/
source
/
wbtris.c.pp
/
wbtris.c
Wrap
C/C++ Source or Header
|
1996-01-01
|
48KB
|
1,489 lines
/*
*******************************************************************************
* *
* *
* WW WW BBBBBBBB TTTTTTTTTT RRRRRRRR II SSSSSSS *
* WW WW BB BB TT RR RR II SS SS *
* WW WW WW BB BB TT RR RR II SS *
* WW WWWW WW BBBBBBB TT RR RRR II SSSSSSS *
* WW WW WW WW BB BB TT RRRRRR II SS *
* WWWW WWWW BB BB TT RR RR II SS *
* WWW WWW BB BB TT RR RR II SS SS *
* WW WW BBBBBBBB TT RR RR II SSSSSSS *
* *
* *
* COPYRIGHT ⌐ 1993 by Dirk B÷hmer ( medusa@uni-paderborn.de ) *
* *
* & Ralf Pieper *
* *
* All rights reserved. *
* *
* *
*******************************************************************************
*/
#include "WBTRIS.h"
#include "Tiles.h"
#include "TilesNI.h"
#include "Logo.h"
#include "pause.h"
#define TEMPLATE "LEFT=LEFTEDGE/N/K,TOP=TOPEDGE/N/K,N=NAME/K,NOLOCK=NOLOCKNAME/K/S\
,NONEXT=SHOWNONEXT/K/S,NOLACE/K/S,LEVEL/N/K\
,PULLDOWNTICKS/N/K\
,R=MOVERIGHT/K,L=MOVELEFT/K,RR=ROTATERIGHT/K,RL=ROTATELEFT/K\
,D=MOVEDOWN/K,DQ=MOVEDOWNQUICK/K"
char versionstring[] = "\0$VER: " PROG_NAME VERSION " " "von " AUTHOR;
UBYTE *CYCLELabels[] = {
(UBYTE *)"Pause",
(UBYTE *)"Go on",
NULL };
;
struct obj {
BOOL objData[4][4];
int color;
};
struct obj objects[8];
int field[YSIZE+1][XSIZE+2] = {
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,-1},
{-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1}
};
short LGXOS;
short LGYOS;
short BOXXSIZE;
short BOXYSIZE;
short NEXTXOFFSET;
short MAINXOFFSET;
BOOL UseLace = TRUE;
short boxxsize;
short boxysize;
int Highscore;
int Score = 0;
int Lines = 0;
int time = DEFAULTTICKS;
int oldtime = DEFAULTTICKS;
int x = XSIZE/2;
int y = 0;
UWORD CursorUp = CURSOR_UP;
UWORD CursorDown = CURSOR_DOWN;
UWORD CursorLeft = CURSOR_LEFT;
UWORD CursorRight = CURSOR_RIGHT;
UWORD NormalSpace = SPACE ;
UWORD QuickSpace = QUICKSPACE;
/* Timer */
BYTE TimerError = 0;
struct MsgPort *TimerMP = NULL;
struct timerequest *TimerIO = NULL;
struct Message *TimerMSG = NULL;
/* Options */
char Name[25];
BOOL SpacePressed = FALSE;
BOOL lockname = TRUE;
BOOL nextteil = TRUE;
int LevelOffset = 0;
int pulldownticks = 0;
int WBTRIS_Window_Top = MAINWINDOWTOP;
int WBTRIS_Window_Left= MAINWINDOWLEFT;
struct Library *IntuitionBase = NULL;
struct Library *KeymapBase = NULL;
struct Library *IconBase = NULL;
struct Window *window = NULL;
struct obj *objptr = NULL;
struct obj *nextptr = NULL;
struct Screen *myscreen = NULL;
struct TextFont *font = NULL, *font2 = NULL;
int LineCounter = 0;
int Level;
struct TextAttr helvetica13 = {"helvetica.font", 13, 0, 0};
struct TextAttr topaz8 = {"topaz.font", 8, 0, 0};
APTR VisualInfo = NULL;
struct Gadget *TetrisGList = NULL;
struct Gadget *TetrisGadgets[9];
BOOL vonoptions = TRUE;
int obj1 = 0;
int obj2 = 0;
int obj3 = 0;
int obj4 = 0;
int obj5 = 0;
int obj6 = 0;
int obj7 = 0;
int wbmain(struct WBStartup *wbs)
{
struct DiskObject *dobj = NULL;
char **toolsarray;
char *s;
char *tail;
if ((IconBase = OpenLibrary("icon.library", 37l)) == NULL)
exit(FALSE);
CurrentDir(wbs->sm_ArgList->wa_Lock);
if (dobj = (struct DiskObject *) GetDiskObject(wbs->sm_ArgList->wa_Name)) {
toolsarray = (char **) dobj->do_ToolTypes;
if (s = (char *) FindToolType(toolsarray, "LEFTEDGE"))
WBTRIS_Window_Left = atoi(s);
if (s = (char *) FindToolType(toolsarray, "TOPEDGE"))
WBTRIS_Window_Top = atoi(s);
if (s = (char *) FindToolType(toolsarray, "NAME"))
strcpy(Name, s);
if (s = (char *) FindToolType(toolsarray, "LOCKNAME")) {
if ((strcmp(s, "TRUE")) == NULL)
lockname = TRUE;
else
lockname = FALSE;
}
if (s = (char *) FindToolType(toolsarray, "SHOWNEXT")) {
if ((strcmp(s, "TRUE")) == NULL)
nextteil = TRUE;
else
nextteil = FALSE;
}
if (s = (char *) FindToolType(toolsarray, "USELACE")) {
if ((strcmp(s, "TRUE")) == NULL)
UseLace = TRUE;
else
UseLace = FALSE;
}
if (s = (char *) FindToolType(toolsarray, "LEVEL"))
LevelOffset = atoi(s);
if (s = (char *) FindToolType(toolsarray, "PULLDOWNTICKS"))
pulldownticks = 20 - atoi(s);
if (s = (char *) FindToolType(toolsarray, "MOVERIGHT"))
CursorRight = strtol(s, &tail, 0);
if (s = (char *) FindToolType(toolsarray, "MOVELEFT"))
CursorLeft = strtol(s, &tail, 0);
if (s = (char *) FindToolType(toolsarray, "ROTATERIGHT"))
CursorUp = strtol(s, &tail, 0);
if (s = (char *) FindToolType(toolsarray, "ROTATELEFT"))
CursorDown = strtol(s, &tail, 0);
if (s = (char *) FindToolType(toolsarray, "MOVEDOWN"))
NormalSpace = strtol(s, &tail, 0);
if (s = (char *) FindToolType(toolsarray, "MOVEDOWNQUICK"))
QuickSpace = strtol(s, &tail, 0);
FreeDiskObject(dobj);
}
if (IconBase)
CloseLibrary(IconBase);
Real_Main();
}
int main(void)
{
int i;
long options[14];
struct RDArgs *args;
for (i=0; i<14; i++)
options[i] = 0L;
args = ReadArgs(TEMPLATE, options, NULL);
if (args) {
if (options[0])
WBTRIS_Window_Left = *(int *) options[0];
if (options[1])
WBTRIS_Window_Top = *(int *) options[1];
if (options[2])
strcpy(Name, (char *) options[2]);
if (options[3])
lockname = !options[3];
if (options[4])
nextteil = options[4];
if (options[5])
UseLace = !options[5];
if (options[6])
LevelOffset = *(int *) options[6];
if (options[7])
pulldownticks = 20 - *(int *) options[7];
if (options[8])
CursorRight = (UWORD) strtol((char *) options[8], NULL, 0);
if (options[9])
CursorLeft = (UWORD) strtol((char *) options[9], NULL, 0);
if (options[10])
CursorUp = (UWORD) strtol((char *) options[10], NULL, 0);
if (options[11])
CursorDown = (UWORD) strtol((char *) options[11], NULL, 0);
if (options[12])
NormalSpace = (UWORD) strtol((char *) options[12], NULL, 0);
if (options[13])
QuickSpace = (UWORD) strtol((char *) options[13], NULL, 0);
}
if (args)
FreeArgs(args);
Real_Main();
}
int Real_Main(void)
{
struct IntuiMessage *imsg;
struct InputEvent inputevent = {0};
struct RastPort *rp;
struct DateStamp DS;
struct Gadget *gad;
UWORD lc, tc;
LONG windowsignal, timersignal;
COUNT i;
BOOL Done = FALSE;
APTR *eventptr;
long mask;
struct I0ExtSer *reply;
InitObjects();
openall(); /* open Fonts, Libraries, VisualInfo, etc*/
if (UseLace) {
LGXOS = 5;
LGYOS = 0;
boxxsize = BOXXSIZE = 18;
boxysize = BOXYSIZE = 16;
NEXTXOFFSET = 14;
MAINXOFFSET = 122;
} else {
LGXOS = 15;
LGYOS = 15;
boxxsize = BOXXSIZE = 16;
boxysize = BOXYSIZE = 8;
NEXTXOFFSET = 155;
MAINXOFFSET = 252;
}
/* OpenOptions(WBTRIS_Window_Left, WBTRIS_Window_Top); */
gad = CreateAllGadgets(myscreen);
window = OpenWindowTags(NULL,
WA_Left, WBTRIS_Window_Left,
WA_Top, WBTRIS_Window_Top,
WA_Width, XSIZE*boxxsize + 35 + MAINXOFFSET,
WA_Height, YSIZE*boxysize + 15 + YOFFSET,
WA_Title, "WBTRIS ⌐ 1993 by Dirk B÷hmer & Ralf Pieper",
WA_Flags, WFLG_CLOSEGADGET | WFLG_ACTIVATE | WFLG_DRAGBAR | WFLG_DEPTHGADGET ,
WA_Gadgets, TetrisGList,
WA_IDCMP, BUTTONIDCMP | NUMBERIDCMP | IDCMP_REFRESHWINDOW | IDCMP_RAWKEY | IDCMP_CLOSEWINDOW
| WFLG_DEPTHGADGET | WFLG_SMART_REFRESH | IDCMP_ACTIVEWINDOW | IDCMP_INACTIVEWINDOW,
TAG_DONE);
if (window == NULL)
closeout("Can't open window",RETURN_FAIL);
rp = window->RPort;
x = XSIZE/2 - 1;
Level = LevelOffset;
oldtime = time = DEFAULTTICKS - Level*2;
nextptr = RandomObject();
objptr = RandomObject();
y = 0;
if (InFirstLine(objptr) == TRUE)
y = 1;
if (nextteil == TRUE)
Draw_NextObject(rp, nextptr);
GT_RefreshWindow( window, NULL );
DrawWindow(rp);
timersignal = 1L << TimerMP->mp_SigBit;
windowsignal = 1L << window->UserPort->mp_SigBit;
/* Initialize InputEvent structure (already cleared to 0) */
inputevent.ie_Class = IECLASS_RAWKEY;
Highscore = Loadhiscore();
GT_SetGadgetAttrs(TetrisGadgets[GD_HighscoreGadget], window, NULL,
GTNM_Number, (ULONG)Highscore,
TAG_END);
GT_SetGadgetAttrs(TetrisGadgets[GD_LevelGadget], window, NULL,
GTNM_Number, (ULONG)Level, TAG_END);
TimerIO->tr_node.io_Command = TR_ADDREQUEST;
TimerIO->tr_time.tv_secs = 0;
TimerIO->tr_time.tv_micro = time * 20000;
SendIO((struct IORequest *) TimerIO);
while(!Done) {
mask = Wait(timersignal | windowsignal);
/*
** Signal kommt vom Timer
*/
if (mask & timersignal) {
while(reply = (struct I0ExtSer *)GetMsg(TimerMP))
{
/* we don't need these messages */
}
AbortIO((struct IORequest *) TimerIO);
WaitIO((struct IORequest *) TimerIO);
/* if (SpacePressed) {
TimerIO->tr_node.io_Command = TR_ADDREQUEST;
TimerIO->tr_time.tv_secs = 0;
TimerIO->tr_time.tv_micro = pulldownticks/2 * 20000;
SendIO((struct IORequest *) TimerIO);
} else { */
TimerIO->tr_node.io_Command = TR_ADDREQUEST;
TimerIO->tr_time.tv_secs = 0;
TimerIO->tr_time.tv_micro = time * 20000;
SendIO((struct IORequest *) TimerIO);
/* }*/
if (CollisionDown(objptr, field, x, y) == FALSE) {
AbortIO((struct IORequest *) TimerIO);
WaitIO((struct IORequest *) TimerIO);
time = oldtime;
SetNewMatrix(objptr, field, x, y);
CleanUp(rp, field);
Done = GameOver(rp,field,lockname);
if (Done == FALSE) {
objptr = nextptr;
nextptr = RandomObject();
y = 0 ;
if (InFirstLine(objptr) == TRUE)
y = 1;
x = XSIZE/2 - 1;
ClearNextField(rp);
if (nextteil == TRUE)
Draw_NextObject(rp , nextptr);
}
} else {
Draw_Object(rp, x, y, objptr, FALSE);
y=y+1;
Draw_Object(rp, x, y, objptr, TRUE);
}
}
/*
** Signal kommt von Gadgets, Fenster, Tasten, usw.
*/
if (mask & windowsignal) {
while (imsg = (struct IntuiMessage *)GetMsg(window->UserPort)) {
switch(imsg->Class) {
case IDCMP_GADGETUP:
gad = (struct Gadget *)imsg->IAddress;
switch(gad->GadgetID) {
case GD_PauseGadget:
Done = Pause(rp, window, field);
break;
case GD_NewGadget:
NewGame(rp, field, FALSE, FALSE);
break;
case GD_QuitGadget:
QuitGame();
Done = TRUE;
break;
case GD_OptGadget:
OpenOptions(window->LeftEdge, window->TopEdge);
NewGame(rp, field, FALSE, TRUE);
break;
}
break;
case IDCMP_REFRESHWINDOW:
/* This handling is REQUIRED with GadTools. */
GT_BeginRefresh(window);
GT_EndRefresh(window, TRUE);
break;
case IDCMP_INACTIVEWINDOW:
WaitForActivateWindow(rp);
break;
case IDCMP_CLOSEWINDOW:
QuitGame();
Done = TRUE;
break;
case IDCMP_RAWKEY:
inputevent.ie_Code = imsg->Code;
inputevent.ie_Qualifier = imsg->Qualifier;
if (imsg->Code == CursorUp) {
if (Rotate_Matrixl(objptr, field, x, y)) {
Rotate_Matrixr(objptr, field, x, y);
Draw_Object(rp, x, y, objptr, FALSE);
Rotate_Matrixl(objptr, field, x, y);
Draw_Object(rp, x, y, objptr, TRUE);
}
} else {
if (imsg->Code == CursorDown) {
if (Rotate_Matrixr(objptr, field, x, y)) {
Rotate_Matrixl(objptr, field, x, y);
Draw_Object(rp, x, y, objptr, FALSE);
Rotate_Matrixr(objptr, field, x, y);
Draw_Object(rp, x, y, objptr, TRUE);
}
} else {
if (imsg->Code == CursorLeft) {
if (CollisionLeft(objptr, field, x, y) == TRUE) {
Draw_Object(rp, x, y, objptr, FALSE);
x = x-1;
Draw_Object(rp, x, y, objptr, TRUE);
}
} else {
if (imsg->Code == CursorRight) {
if (CollisionRight(objptr, field, x, y) == TRUE) {
Draw_Object(rp, x, y, objptr, FALSE);
x=x+1;
Draw_Object(rp, x, y, objptr, TRUE);
}
} else {
if (imsg->Code == NormalSpace) {
if (!SpacePressed) {
AbortIO((struct IORequest *) TimerIO);
WaitIO((struct IORequest *) TimerIO);
SpacePressed = TRUE;
oldtime = time;
time = pulldownticks;
}
} else {
if (imsg->Code == QuickSpace) {
AbortIO((struct IORequest *) TimerIO);
WaitIO((struct IORequest *) TimerIO);
oldtime = time;
time = 0;
} else {
if (SpacePressed) {
SpacePressed = FALSE;
time = oldtime;
}
}}}}}}
break;
default:
}
ReplyMsg((struct Message *)imsg);
}
}
}
closeall();
exit(RETURN_OK);
}
/*
** Fragt die Kollision nach rechts ab
** FALSE, wenn Object oder rechte Wand im Weg
** TRUE , wenn Object nach rechts verschoben werden kann
*/
BOOL CollisionRight(struct obj *objptr, int field[YSIZE+1][XSIZE+2], int x, int y)
{
short i,j;
for (j=3; j>=0; j--)
for (i=0; i<4; i++) {
if ((objptr->objData[i][j] > 0) && (field[y+i-1][j+x+1] != 0))
return(FALSE);
}
return(TRUE);
}
/*
** Fragt die Kollision nach links ab
** FALSE, wenn Object oder linke Wand im Weg
** TRUE , wenn Object nach links verschoben werden kann
*/
BOOL CollisionLeft(struct obj *objptr, int field[YSIZE+1][XSIZE+2], int x, int y)
{
short i,j;
for (j=0; j<4; j++)
for (i=0; i<4; i++) {
if ((objptr->objData[i][j] > 0) && (field[y+i-1][j+x-1] != 0))
return(FALSE);
}
return(TRUE);
}
/*
** Fragt die Kollision nach unten ab
** FALSE, wenn Object oder Boden im Weg
** TRUE , wenn Object nach unten verschoben werden kann
*/
BOOL CollisionDown(struct obj *objptr, int field[YSIZE+1][XSIZE+2], int x, int y)
{
short i,j;
for (j=0; j<4; j++)
for (i=0; i<4; i++) {
if ((objptr->objData[i][j] > 0) && (field[y+i][j+x] != 0)) {
Score = Score + 1;
return(FALSE);
}
}
return(TRUE);
}
void openall(void)
{
if ((TimerMP = CreatePort(NULL, NULL)) == NULL)
closeout("Couldn't create messageport", RETURN_FAIL);
if ((TimerIO = (struct timerequest *) CreateExtIO(TimerMP, sizeof(struct timerequest))) == NULL)
closeout("Couldn't create IOrequest", RETURN_FAIL);
if ((TimerError = OpenDevice(TIMERNAME, UNIT_VBLANK, (struct IORequest *) TimerIO, 0L)) != NULL)
closeout("Couldn't open timer.device", RETURN_FAIL);
if ((KeymapBase = OpenLibrary("keymap.library", 37)) == NULL)
closeout("Kickstart 2.0 required",RETURN_FAIL);
if ((IntuitionBase = OpenLibrary("intuition.library", 37)) == NULL)
closeout("Can't open intuition",RETURN_FAIL);
if ((font = OpenDiskFont(&helvetica13)) == NULL)
closeout("Failed to open Helvetica 13", RETURN_FAIL);
if ((font2 = OpenDiskFont(&topaz8)) == NULL)
closeout("Failed to open Topaz 8", RETURN_FAIL);
if ((myscreen = LockPubScreen(NULL)) == NULL)
closeout("Couldn't lock default public screen", RETURN_FAIL);
if ((myscreen->Height) < 450)
UseLace = FALSE;
if ((VisualInfo = GetVisualInfo(myscreen, TAG_END)) == NULL)
closeout("GetVisualInfo() failed", RETURN_FAIL);
}
void closeall(void)
{
AbortIO((struct IORequest *) TimerIO);
WaitIO((struct IORequest *) TimerIO);
if (window)
CloseWindow(window);
if (TetrisGList)
FreeGadgets(TetrisGList);
if (VisualInfo)
FreeVisualInfo(VisualInfo);
if (myscreen)
UnlockPubScreen(NULL, myscreen);
if (IntuitionBase)
CloseLibrary(IntuitionBase);
if (KeymapBase)
CloseLibrary(KeymapBase);
if (!TimerError)
CloseDevice((struct IORequest *) TimerIO);
if (TimerIO)
DeleteExtIO((struct IORequest *) TimerIO);
if (TimerMP)
DeletePort(TimerMP);
exit(0);
}
void closeout(UBYTE *errstring, LONG rc)
{
struct EasyStruct myES = {
sizeof(struct EasyStruct),
0,
"WBTRIS Error",
"Error: %s\n",
"OK",
};
if (*errstring)
EasyRequest(NULL, &myES, NULL, errstring);
closeall();
exit(rc);
}
BOOL Rotate_Matrixr(struct obj *objptr, int field[YSIZE+1][XSIZE+2], int x, int y)
{
short i, j;
struct obj b[1];
b[0].objData[3][0] = objptr->objData[0][0];
b[0].objData[2][0] = objptr->objData[0][1];
b[0].objData[1][0] = objptr->objData[0][2];
b[0].objData[0][0] = objptr->objData[0][3];
b[0].objData[3][1] = objptr->objData[1][0];
b[0].objData[2][1] = objptr->objData[1][1];
b[0].objData[1][1] = objptr->objData[1][2];
b[0].objData[0][1] = objptr->objData[1][3];
b[0].objData[3][2] = objptr->objData[2][0];
b[0].objData[2][2] = objptr->objData[2][1];
b[0].objData[1][2] = objptr->objData[2][2];
b[0].objData[0][2] = objptr->objData[2][3];
b[0].objData[3][3] = objptr->objData[3][0];
b[0].objData[2][3] = objptr->objData[3][1];
b[0].objData[1][3] = objptr->objData[3][2];
b[0].objData[0][3] = objptr->objData[3][3];
if ((CollisionRight(b, field, x-1, y) == TRUE) && (CollisionLeft(b, field, x+1, y) == TRUE) && (CollisionDown(b, field, x, y-1) == TRUE)) {
for (i=0; i<4; i++)
for (j=0; j<4; j++)
objptr->objData[i][j] = b[0].objData[i][j];
return(TRUE);
}
return(FALSE);
}
BOOL Rotate_Matrixl(struct obj *objptr, int field[YSIZE+1][XSIZE+2], int x, int y)
{
short i, j;
struct obj b[1];
b[0].objData[0][3] = objptr->objData[0][0];
b[0].objData[1][3] = objptr->objData[0][1];
b[0].objData[2][3] = objptr->objData[0][2];
b[0].objData[3][3] = objptr->objData[0][3];
b[0].objData[0][2] = objptr->objData[1][0];
b[0].objData[1][2] = objptr->objData[1][1];
b[0].objData[2][2] = objptr->objData[1][2];
b[0].objData[3][2] = objptr->objData[1][3];
b[0].objData[0][1] = objptr->objData[2][0];
b[0].objData[1][1] = objptr->objData[2][1];
b[0].objData[2][1] = objptr->objData[2][2];
b[0].objData[3][1] = objptr->objData[2][3];
b[0].objData[0][0] = objptr->objData[3][0];
b[0].objData[1][0] = objptr->objData[3][1];
b[0].objData[2][0] = objptr->objData[3][2];
b[0].objData[3][0] = objptr->objData[3][3];
if ((CollisionRight(b, field, x-1, y) == TRUE) && (CollisionLeft(b, field, x+1, y) == TRUE) && (CollisionDown(b, field, x, y-1) == TRUE)) {
for (i=0; i<4; i++)
for (j=0; j<4; j++)
objptr->objData[i][j] = b[0].objData[i][j];
return(TRUE);
}
return(FALSE);
}
void Draw_NextObject(struct RastPort *rp, struct obj *objptr)
{
short i,j;
for (i=0; i<4; i++) {
for (j=0; j<4; j++)
if (objptr->objData[i][j] > 0)
Draw_Box(rp, j-5, i, objptr->color, TRUE);
}
}
void ClearNextField(struct RastPort *rp)
{
short i,j;
for (i=0; i<4; i++) {
for (j=0; j<4; j++)
Draw_Box(rp, j-5, i, 0, FALSE);
}
}
void Draw_Object(struct RastPort *rp, int x, int y, struct obj *objptr, BOOL malen)
{
short i,j;
for (i=0; i<4; i++) {
for (j=0; j<4; j++)
if (objptr->objData[i][j] > 0)
Draw_Box(rp, x+j, y+i-1, objptr->color, malen);
}
}
void Draw_Box(struct RastPort *rp, int x, int y, int color, int malen)
{
if (UseLace) {
if (malen == TRUE) {
switch(color) {
case 1:
DrawImage(rp, &GruenWeiss, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 2:
DrawImage(rp, &GruenWeissSchach, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 3:
DrawImage(rp, &GruenWeissSchraeg, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 4:
DrawImage(rp, &Schwarz, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 5:
DrawImage(rp, &SchwarzGruen, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 6:
DrawImage(rp, &SchwarzWeiss, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 7:
DrawImage(rp, &Gruen, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
}
} else {
switch(color) {
case 0:
SetAPen(rp, 0);
RectFill(rp, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize, MAINXOFFSET + x*boxxsize + BOXXSIZE, YOFFSET + y*boxysize + BOXYSIZE);
break;
case 1:
EraseImage(rp, &GruenWeiss, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 2:
EraseImage(rp, &GruenWeissSchach, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 3:
EraseImage(rp, &GruenWeissSchraeg, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 4:
EraseImage(rp, &Schwarz, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 5:
EraseImage(rp, &SchwarzGruen, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 6:
EraseImage(rp, &SchwarzWeiss, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 7:
EraseImage(rp, &Gruen, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
}
}
} else {
if (malen == TRUE) {
switch(color) {
case 1:
DrawImage(rp, &GruenWeissNI, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 2:
DrawImage(rp, &GruenWeissSchachNI, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 3:
DrawImage(rp, &GruenWeissSchraegNI, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 4:
DrawImage(rp, &SchwarzNI, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 5:
DrawImage(rp, &SchwarzGruenNI, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 6:
DrawImage(rp, &SchwarzWeissNI, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 7:
DrawImage(rp, &GruenNI, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
}
} else {
switch(color) {
case 0:
SetAPen(rp, 0);
RectFill(rp, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize, MAINXOFFSET + x*boxxsize + BOXXSIZE, YOFFSET + y*boxysize + BOXYSIZE);
break;
case 1:
EraseImage(rp, &GruenWeissNI, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 2:
EraseImage(rp, &GruenWeissSchachNI, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 3:
EraseImage(rp, &GruenWeissSchraegNI, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 4:
EraseImage(rp, &SchwarzNI, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 5:
EraseImage(rp, &SchwarzGruenNI, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 6:
EraseImage(rp, &SchwarzWeissNI, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
case 7:
EraseImage(rp, &GruenNI, MAINXOFFSET + x*boxxsize, YOFFSET + y*boxysize);
break;
}
}
}
}
struct obj *RandomObject(void)
{
static ULONG RandomResult = 0L; /* So the last random-number is still stored ! */
ULONG Sec,Mic;
CurrentTime((LONG *)&Sec,(LONG *)&Mic);
RandomResult *= Sec;
RandomResult += Mic;
while (RandomResult > 32767L) RandomResult = RandomResult>>1;
RandomResult = RandomResult % 7;
UpdateStatistic(RandomResult);
switch(RandomResult) {
case 0:
return(&objects[1]);
break;
case 1:
return(&objects[2]);
break;
case 2:
return(&objects[3]);
break;
case 3:
return(&objects[4]);
break;
case 4:
return(&objects[5]);
break;
case 5:
return(&objects[6]);
break;
default:
return(&objects[7]);
}
}
void DrawWindow(struct RastPort *rp)
{
/* Mainfield */
if (UseLace)
DrawBevelBox(rp, MAINXOFFSET+14, YOFFSET-2, (XSIZE+1)*boxxsize-10, YSIZE*boxysize+5, GT_VisualInfo, VisualInfo);
else
DrawBevelBox(rp, MAINXOFFSET+13, YOFFSET-2, (XSIZE+1)*boxxsize-10, YSIZE*boxysize+5, GT_VisualInfo, VisualInfo);
/* Next Object Field */
DrawBevelBox(rp, NEXTXOFFSET+14, YOFFSET-2, 5*boxxsize-10, 4*boxysize+4, GTBB_Recessed, TRUE, GT_VisualInfo, VisualInfo);
/* Logo */
if (UseLace)
DrawImage(rp, &logo, LGXOS + 20, LGYOS + 320);
else
DrawImage(rp, &logo, LGXOS, LGYOS + 3);
}
void SetNewMatrix(struct obj *objptr, int field[YSIZE+1][XSIZE+2], int x, int y)
{
short line, column;
for (line=0; line<4; line++)
for (column=0; column<4; column++) {
if (objptr->objData[line][column] == 1)
field[y+line-1][x+column] = objptr->color;
}
}
void CleanUp(struct RastPort *rp, int field[YSIZE+1][XSIZE+2])
{
int i, j, line, column;
BOOL Update = FALSE;
BOOL KeineNull = TRUE;
Lines = 0;
for (line=1; line < YSIZE; line++) {
for (column=1; column < XSIZE+1; column++)
if (field[line][column] == 0)
KeineNull = FALSE;
if (KeineNull == TRUE)
{
Lines++;
Update = TRUE;
for (j=line; j>0; j--)
for (i=1; i<XSIZE+1; i++)
field[j][i] = field[j-1][i];
}
KeineNull = TRUE;
}
if (Update == TRUE) {
for (line=1; line < YSIZE; line++) {
for (column=1; column < XSIZE+1; column++)
switch(field[line][column]) {
case 0:
Draw_Box(rp, column, line, 0, FALSE);
break;
case 1:
Draw_Box(rp, column, line, 1, TRUE);
break;
case 2:
Draw_Box(rp, column, line, 2, TRUE);
break;
case 3:
Draw_Box(rp, column, line, 3, TRUE);
break;
case 4:
Draw_Box(rp, column, line, 4, TRUE);
break;
case 5:
Draw_Box(rp, column, line, 5, TRUE);
break;
case 6:
Draw_Box(rp, column, line, 6, TRUE);
break;
case 7:
Draw_Box(rp, column, line, 7, TRUE);
break;
}
}
}
LineCounter = LineCounter + Lines;
Level = LineCounter / 10 + LevelOffset;
if (Level >= 20)
oldtime = 0;
else
oldtime = DEFAULTTICKS - Level*2;
time = oldtime;
Score = Score + 10*Lines*Lines;
GT_SetGadgetAttrs(TetrisGadgets[GD_ScoreGadget], window, NULL,
GTNM_Number, (ULONG)Score,
TAG_END);
GT_SetGadgetAttrs(TetrisGadgets[GD_LevelGadget], window, NULL,
GTNM_Number, (ULONG)Level,
TAG_END);
GT_SetGadgetAttrs(TetrisGadgets[GD_LineGadget], window, NULL,
GTNM_Number, (ULONG)LineCounter,
TAG_END);
}
/*
** Ist der obere Rand erreicht, dann ist das Spiel zu Ende
** TRUE, wenn oberer Rand erreicht
** FALSE, wenn nicht
*/
BOOL GameOver(struct RastPort *rp, int field[YSIZE+1][XSIZE+2],BOOL lockname)
{
int column;
for (column=0; column<=XSIZE; column++) {
if (field[1][column] > 0) {
if (Score > Highscore)
Highscore = Score;
Enterhighscore(window, Score, LineCounter);
if ((AskContinue()) == TRUE) {
Score = 0;
LineCounter = 0;
Level = LevelOffset;
if (lockname == TRUE) {
NewGame(rp, field, TRUE, FALSE);
} else {
OpenOptions(window->LeftEdge, window->TopEdge);
NewGame(rp, field, TRUE, TRUE);
}
}
else {
return(TRUE);
}
}
}
return(FALSE);
}
/*
** Hier wird den Objekten die Form und die Farbe gegeben
*/
void InitObjects(void)
{
objects[0].objData[0][0] = 0; objects[0].objData[0][1] = 0; objects[0].objData[0][2] = 0; objects[0].objData[0][3] = 0;
objects[0].objData[1][0] = 0; objects[0].objData[1][1] = 0; objects[0].objData[1][2] = 0; objects[0].objData[1][3] = 0;
objects[0].objData[2][0] = 0; objects[0].objData[2][1] = 0; objects[0].objData[2][2] = 0; objects[0].objData[2][3] = 0;
objects[0].objData[3][0] = 0; objects[0].objData[3][1] = 0; objects[0].objData[3][2] = 0; objects[0].objData[3][3] = 0;
objects[0].color = 0;
objects[1].objData[0][0] = 0; objects[1].objData[0][1] = 0; objects[1].objData[0][2] = 0; objects[1].objData[0][3] = 0;
objects[1].objData[1][0] = 0; objects[1].objData[1][1] = 1; objects[1].objData[1][2] = 1; objects[1].objData[1][3] = 0;
objects[1].objData[2][0] = 0; objects[1].objData[2][1] = 1; objects[1].objData[2][2] = 1; objects[1].objData[2][3] = 0;
objects[1].objData[3][0] = 0; objects[1].objData[3][1] = 0; objects[1].objData[3][2] = 0; objects[1].objData[3][3] = 0;
objects[1].color = 1;
objects[2].objData[0][0] = 0; objects[2].objData[0][1] = 1; objects[2].objData[0][2] = 0; objects[2].objData[0][3] = 0;
objects[2].objData[1][0] = 0; objects[2].objData[1][1] = 1; objects[2].objData[1][2] = 0; objects[2].objData[1][3] = 0;
objects[2].objData[2][0] = 0; objects[2].objData[2][1] = 1; objects[2].objData[2][2] = 0; objects[2].objData[2][3] = 0;
objects[2].objData[3][0] = 0; objects[2].objData[3][1] = 1; objects[2].objData[3][2] = 0; objects[2].objData[3][3] = 0;
objects[2].color = 2;
objects[3].objData[0][0] = 0; objects[3].objData[0][1] = 0; objects[3].objData[0][2] = 0; objects[3].objData[0][3] = 0;
objects[3].objData[1][0] = 0; objects[3].objData[1][1] = 0; objects[3].objData[1][2] = 1; objects[3].objData[1][3] = 0;
objects[3].objData[2][0] = 0; objects[3].objData[2][1] = 1; objects[3].objData[2][2] = 1; objects[3].objData[2][3] = 0;
objects[3].objData[3][0] = 0; objects[3].objData[3][1] = 0; objects[3].objData[3][2] = 1; objects[3].objData[3][3] = 0;
objects[3].color = 3;
objects[4].objData[0][0] = 0; objects[4].objData[0][1] = 0; objects[4].objData[0][2] = 0; objects[4].objData[0][3] = 0;
objects[4].objData[1][0] = 1; objects[4].objData[1][1] = 1; objects[4].objData[1][2] = 1; objects[4].objData[1][3] = 0;
objects[4].objData[2][0] = 0; objects[4].objData[2][1] = 0; objects[4].objData[2][2] = 1; objects[4].objData[2][3] = 0;
objects[4].objData[3][0] = 0; objects[4].objData[3][1] = 0; objects[4].objData[3][2] = 0; objects[4].objData[3][3] = 0;
objects[4].color = 4;
objects[5].objData[0][0] = 0; objects[5].objData[0][1] = 0; objects[5].objData[0][2] = 0; objects[5].objData[0][3] = 0;
objects[5].objData[1][0] = 0; objects[5].objData[1][1] = 0; objects[5].objData[1][2] = 1; objects[5].objData[1][3] = 0;
objects[5].objData[2][0] = 1; objects[5].objData[2][1] = 1; objects[5].objData[2][2] = 1; objects[5].objData[2][3] = 0;
objects[5].objData[3][0] = 0; objects[5].objData[3][1] = 0; objects[5].objData[3][2] = 0; objects[5].objData[3][3] = 0;
objects[5].color = 5;
objects[6].objData[0][0] = 0; objects[6].objData[0][1] = 1; objects[6].objData[0][2] = 0; objects[6].objData[0][3] = 0;
objects[6].objData[1][0] = 0; objects[6].objData[1][1] = 1; objects[6].objData[1][2] = 1; objects[6].objData[1][3] = 0;
objects[6].objData[2][0] = 0; objects[6].objData[2][1] = 0; objects[6].objData[2][2] = 1; objects[6].objData[2][3] = 0;
objects[6].objData[3][0] = 0; objects[6].objData[3][1] = 0; objects[6].objData[3][2] = 0; objects[6].objData[3][3] = 0;
objects[6].color = 6;
objects[7].objData[0][0] = 0; objects[7].objData[0][1] = 0; objects[7].objData[0][2] = 0; objects[7].objData[0][3] = 0;
objects[7].objData[1][0] = 0; objects[7].objData[1][1] = 0; objects[7].objData[1][2] = 1; objects[7].objData[1][3] = 0;
objects[7].objData[2][0] = 0; objects[7].objData[2][1] = 1; objects[7].objData[2][2] = 1; objects[7].objData[2][3] = 0;
objects[7].objData[3][0] = 0; objects[7].objData[3][1] = 1; objects[7].objData[3][2] = 0; objects[7].objData[3][3] = 0;
objects[7].color = 7;
}
/*
** Das Programm kann angehalten werden
*/
BOOL Pause(struct RastPort *rp, struct Window *window, int field[YSIZE+1][XSIZE+2])
{
BOOL Done = FALSE;
LONG windowsignal;
struct IntuiMessage *imsg;
struct Gadget *gad;
int line,column;
GT_SetGadgetAttrs(TetrisGadgets[GD_PauseGadget], window, NULL,
GTCY_Labels, &CYCLELabels[1], TAG_END);
GT_SetGadgetAttrs(TetrisGadgets[GD_NewGadget], window, NULL,
GA_Disabled, TRUE, TAG_END);
GT_SetGadgetAttrs(TetrisGadgets[GD_QuitGadget], window, NULL,
GA_Disabled, FALSE, TAG_END);
GT_SetGadgetAttrs(TetrisGadgets[GD_OptGadget], window, NULL,
GA_Disabled, TRUE, TAG_END);
GT_SetGadgetAttrs(TetrisGadgets[GD_StatGadget], window, NULL,
GA_Disabled, FALSE, TAG_END);
SetAPen(rp, 0);
RectFill(rp, MAINXOFFSET+16, YOFFSET-1, MAINXOFFSET+16 + (XSIZE+1)*boxxsize-15, YOFFSET + YSIZE*boxysize+1);
if (UseLace)
DrawImage(rp, &Pausebrush, 190, 150);
else
DrawImage(rp, &Pausebrush, 310, 85);
while(!Done)
{
Wait(1L << window->UserPort->mp_SigBit);
while (imsg = (struct IntuiMessage *)GetMsg(window->UserPort)) {
switch(imsg->Class) {
case IDCMP_GADGETUP:
gad = (struct Gadget *)imsg->IAddress;
switch(gad->GadgetID) {
case GD_PauseGadget:
GT_SetGadgetAttrs(TetrisGadgets[GD_PauseGadget], window, NULL,
GA_Disabled, FALSE, TAG_END);
GT_SetGadgetAttrs(TetrisGadgets[GD_NewGadget], window, NULL,
GA_Disabled, FALSE, TAG_END);
GT_SetGadgetAttrs(TetrisGadgets[GD_QuitGadget], window, NULL,
GA_Disabled, FALSE, TAG_END);
GT_SetGadgetAttrs(TetrisGadgets[GD_StatGadget], window, NULL,
GA_Disabled, TRUE, TAG_END);
GT_SetGadgetAttrs(TetrisGadgets[GD_OptGadget], window, NULL,
GA_Disabled, FALSE, TAG_END);
GT_SetGadgetAttrs(TetrisGadgets[GD_PauseGadget], window, NULL,
GTCY_Labels, &CYCLELabels[0], TAG_END);
Done = TRUE;
break;
case GD_StatGadget:
statistic(window->LeftEdge, window->TopEdge, obj1, obj2, obj3, obj4, obj5, obj6, obj7);
break;
}
if (gad->GadgetID == GD_QuitGadget) {
QuitGame();
closeall();
exit(0);
}
break;
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh(window);
GT_EndRefresh(window, TRUE);
break;
case IDCMP_CLOSEWINDOW:
QuitGame();
closeall();
exit(0);
break;
}
}
}
if (UseLace)
EraseImage(rp, &Pausebrush, 190,150);
else
EraseImage(rp, &Pausebrush, 310,85);
for (line=1; line < YSIZE; line++) {
for (column=1; column < XSIZE+1; column++)
switch(field[line][column]) {
case 0:
Draw_Box(rp, column, line, 0, FALSE);
break;
case 1:
Draw_Box(rp, column, line, 1, TRUE);
break;
case 2:
Draw_Box(rp, column, line, 2, TRUE);
break;
case 3:
Draw_Box(rp, column, line, 3, TRUE);
break;
case 4:
Draw_Box(rp, column, line, 4, TRUE);
break;
case 5:
Draw_Box(rp, column, line, 5, TRUE);
break;
case 6:
Draw_Box(rp, column, line, 6, TRUE);
break;
case 7:
Draw_Box(rp, column, line, 7, TRUE);
break;
}
}
return(FALSE);
}
/*
** Ein neues Spiel starten
*/
void NewGame(struct RastPort *rp, int field[YSIZE+1][XSIZE+2],BOOL vongameover, BOOL vonoptions)
{
int line, column;
/* obj1 = obj2 = obj3 = obj4 = obj5 = obj6 = obj7 = 0;*/
/* Feld loeschen */
for (line=0; line < YSIZE; line++)
for (column=1; column<=XSIZE; column++) {
field[line][column] = 0;
Draw_Box(rp, column, line, 0, FALSE);
}
ClearNextField(rp);
nextptr = RandomObject();
objptr = RandomObject();
if (nextteil == TRUE)
Draw_NextObject(rp, nextptr);
x = XSIZE/2-1;
y = 0;
if (InFirstLine(objptr) == TRUE)
y = 1;
if (Score > Highscore)
Highscore = Score;
if ((vongameover == FALSE) && (vonoptions == FALSE))
Enterhighscore(window, Score, LineCounter);
if (lockname == FALSE)
if (vonoptions == FALSE)
OpenOptions(window->LeftEdge, window->TopEdge);
vongameover = FALSE;
vonoptions = FALSE;
Score = 0;
LineCounter = 0;
Level = LevelOffset;
time = oldtime = DEFAULTTICKS - 2*LevelOffset;
GT_SetGadgetAttrs(TetrisGadgets[GD_HighscoreGadget], window, NULL,
GTNM_Number, (ULONG)Highscore, TAG_END);
GT_SetGadgetAttrs(TetrisGadgets[GD_ScoreGadget], window, NULL,
GTNM_Number, (ULONG)Score, TAG_END);
GT_SetGadgetAttrs(TetrisGadgets[GD_LevelGadget], window, NULL,
GTNM_Number, (ULONG)Level, TAG_END);
GT_SetGadgetAttrs(TetrisGadgets[GD_LineGadget], window, NULL,
GTNM_Number, (ULONG)LineCounter, TAG_END);
}
void QuitGame(void)
{
if (Score > Highscore) {
Highscore = Score;
Enterhighscore(window, Score, LineCounter);
}
}
void Enterhighscore(struct Window *window, int Score, int Rows)
{
WORD xpos, ypos;
xpos = window->LeftEdge;
ypos = window->TopEdge + 70;
HiscoreList(Name, Score, Rows, xpos, ypos);
}
BOOL InFirstLine(struct obj *objptr)
{
int column;
for (column=0; column<4; column++)
if (objptr->objData[0][column] == 1)
return(TRUE);
return(FALSE);
}
int Loadhiscore(void)
{
char score[10];
int zaehler = 0, hiscore = 0, c;
FILE *fp;
char *ptr;
char FName[80];
if (getenv("WBTRIS"))
strcpy(FName, getenv("WBTRIS"));
else
strcpy(FName, FILENAME);
ptr = &score[0];
if ((fp = fopen(FName, "r")) == NULL)
return(0);
else {
while (((c=getc(fp)) != EOF) && (zaehler != 2))
if (c == '/') zaehler++;
if (c != EOF) {
while (c != '/') {
*ptr = c;
ptr++;
c = getc(fp);
}
*ptr = '\0';
hiscore = atoi(score);
}
fclose(fp);
return(hiscore);
}
}
BOOL AskContinue(void)
{
struct EasyStruct myES = {
sizeof(struct EasyStruct),
0,
"Continue",
"Game over\n\nDo you want to play again ?",
"YEA|No thanks",
};
LONG answer;
answer = EasyRequest(NULL, &myES, NULL, "(Variable)");
switch (answer) {
case 1:
return(TRUE);
break;
case 2:
return(FALSE);
break;
}
}
void WaitForActivateWindow(struct RastPort *rp)
{
BOOL Done = FALSE;
struct IntuiMessage *imsg;
int line, column;
SetAPen(rp, 0);
RectFill(rp, MAINXOFFSET+16, YOFFSET-1, MAINXOFFSET+16 + (XSIZE+1)*boxxsize-15, YOFFSET + YSIZE*boxysize+1);
if (UseLace)
DrawImage(rp, &Pausebrush, 190, 150);
else
DrawImage(rp, &Pausebrush, 310, 85);
while(!Done)
{
Wait(1L << window->UserPort->mp_SigBit);
while (imsg = (struct IntuiMessage *)GetMsg(window->UserPort)) {
switch(imsg->Class) {
case IDCMP_ACTIVEWINDOW:
Done = TRUE;
break;
case IDCMP_REFRESHWINDOW:
GT_BeginRefresh(window);
GT_EndRefresh(window, TRUE);
break;
}
}
}
if (UseLace)
EraseImage(rp, &Pausebrush, 190,150);
else
EraseImage(rp, &Pausebrush, 310,85);
for (line=1; line < YSIZE; line++) {
for (column=1; column < XSIZE+1; column++)
switch(field[line][column]) {
case 0:
Draw_Box(rp, column, line, 0, FALSE);
break;
case 1:
Draw_Box(rp, column, line, 1, TRUE);
break;
case 2:
Draw_Box(rp, column, line, 2, TRUE);
break;
case 3:
Draw_Box(rp, column, line, 3, TRUE);
break;
case 4:
Draw_Box(rp, column, line, 4, TRUE);
break;
case 5:
Draw_Box(rp, column, line, 5, TRUE);
break;
case 6:
Draw_Box(rp, column, line, 6, TRUE);
break;
case 7:
Draw_Box(rp, column, line, 7, TRUE);
break;
}
}
}
void UpdateStatistic(int objnumber)
{
switch(objnumber) {
case 0:
obj1++;
break;
case 1:
obj2++;
break;
case 2:
obj3++;
break;
case 3:
obj4++;
break;
case 4:
obj5++;
break;
case 5:
obj6++;
break;
case 6:
obj7++;
break;
}
}